﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AliyunOpenSearch4Net;
using AliyunOpenSearch4Net.Base;
using Newtonsoft.Json;

namespace AliyunOpenSearch4Net.App
{
    class AppStatusRequest : RequestBase<Response<AppStatusResult>>
    {
        public AppStatusRequest()
            : base("status")
        {

        }

        public string AppName { get; set; }
    }

    /// <summary>
    /// App status query result
    /// </summary>
    public class AppStatusResult
    {
        /// <summary>
        /// Gets or sets the name of the index.
        /// </summary>
        /// <value>
        /// The name of the index.
        /// </value>
        [JsonProperty("index_name")]
        public string IndexName { get; set; }

        /// <summary>
        /// Gets or sets the pv.
        /// </summary>
        /// <value>
        /// The pv.
        /// </value>
        [JsonProperty("pv")]
        public int PV { get; set; }

        /// <summary>
        /// Gets or sets the document last update time.
        /// </summary>
        /// <value>
        /// The document last update time.
        /// </value>
        [JsonProperty("doc_last_update_time")]
        [JsonConverter(typeof(UnixTicksDateTimeConverter))]
        public DateTime DocLastUpdateTime { get; set; }

        /// <summary>
        /// Gets or sets the quota.
        /// </summary>
        /// <value>
        /// The quota.
        /// </value>
        [JsonProperty("quota")]
        public AppQuota Quota { get; set; }

        /// <summary>
        /// Gets or sets the fields.
        /// </summary>
        /// <value>
        /// The fields.
        /// </value>
        [JsonProperty("fields")]
        public AppFields Fields { get; set; }
    }

    /// <summary>
    /// The app's fields
    /// </summary>
    public class AppFields
    {
        /// <summary>
        /// Gets or sets from tables.
        /// </summary>
        /// <value>
        /// From tables.
        /// </value>
        [JsonProperty("from_table")]
        public AppFromTables FromTables { get; set; }
    }

    /// <summary>
    /// App from tables collection
    /// </summary>
    public class AppFromTables
    {
        /// <summary>
        /// Gets or sets the tables.
        /// </summary>
        /// <value>
        /// The tables.
        /// </value>
        [JsonProperty("tables")]
        public AppTableCollection Tables { get; set; }
    }

    /// <summary>
    /// App table collection
    /// </summary>
    [JsonConverter(typeof(NamedItemsCollectionConverter<AppTableItem, AppColumnCollection>))]
    public class AppTableCollection : NamedItemsCollection<AppTableItem, AppColumnCollection>
    {

    }

    /// <summary>
    /// App table item
    /// </summary>
    public class AppTableItem : NamedItem<AppColumnCollection>
    {

    }

    /// <summary>
    /// App column collection
    /// </summary>
    [JsonConverter(typeof(NamedItemsCollectionConverter<AppColumnItem, AppColumn>))]
    public class AppColumnCollection : NamedItemsCollection<AppColumnItem, AppColumn>
    {

    }

    /// <summary>
    /// App column item
    /// </summary>
    public class AppColumnItem : NamedItem<AppColumn>
    {

    }

    /// <summary>
    /// App column
    /// </summary>
    public class AppColumn
    {
        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        [JsonProperty("name")]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>
        /// The type.
        /// </value>
        [JsonProperty("type")]
        public string Type { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is multiple value.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is multiple; otherwise, <c>false</c>.
        /// </value>
        [JsonProperty("is_multi")]
        public bool IsMultiple { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is primary key.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is primary key; otherwise, <c>false</c>.
        /// </value>
        [JsonProperty("is_pk")]
        public bool IsPrimaryKey { get; set; }

        /// <summary>
        /// Gets or sets the source.
        /// </summary>
        /// <value>
        /// The source.
        /// </value>
        [JsonProperty("src")]
        public string Src { get; set; }
    }

    /// <summary>
    /// Application's quota
    /// </summary>
    public class AppQuota
    {
        /// <summary>
        /// Gets or sets the instance quota.
        /// </summary>
        /// <value>
        /// The instance quota.
        /// </value>
        [JsonProperty("instance")]
        public AppQuotaInstance Instance { get; set; }

        /// <summary>
        /// Gets or sets the QPS quota.
        /// </summary>
        /// <value>
        /// The QPS quota.
        /// </value>
        [JsonProperty("qps")]
        public AppQuotaInstance QPS { get; set; }
    }

    /// <summary>
    /// App quota instance
    /// </summary>
    public class AppQuotaInstance
    {
        /// <summary>
        /// Gets or sets a value indicating whether [out of limit].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [out of limit]; otherwise, <c>false</c>.
        /// </value>
        [JsonProperty("out_of_limit")]
        public bool OutOfLimit { get; set; }
    }

    /// <summary>
    /// App QPS quota
    /// </summary>
    public class AppQuotaQPS
    {
        /// <summary>
        /// Gets or sets a value indicating whether [out of limit].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [out of limit]; otherwise, <c>false</c>.
        /// </value>
        [JsonProperty("out_of_limit")]
        public bool OutOfLimit { get; set; }
    }
}
